package org.arduomo.irserial;

import java.awt.Dimension;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Set;

import javax.swing.JFrame;

import org.arduomo.irserial.ui.IRRemotePanel;
import org.arduomo.serial.controller.SerialController;

public class Main {

	public static void main(String[] args) throws Exception {
		File file = new File("resources/AKB72915207.txt");
		IRConfig config = IRConfig.parseFile(file);
//		IRRemotePanel panel = new IRRemotePanel(config);
//		JFrame frame = new JFrame();
//		frame.setContentPane(panel);
//		frame.setSize(new Dimension(400,300));
//		frame.setVisible(true);
		
		SerialController controller = new SerialController();
		Reader reader = new InputStreamReader(System.in);
		BufferedReader bufferedReader = new BufferedReader(reader);

		while (true) {
			String command = bufferedReader.readLine();
			
			System.out.println("Command received: " + command);
			String preData = config.getProperty(IRConfig.PRE_DATA);
			String code = config.getCode(command);
			if (code!=null) {
				String message = "sendNEC:" + preData + ":" + code;
				System.out.println(message);
				controller.sendMessage(message);
			}
		}
	}

}
